package com.wpen;

import java.util.concurrent.TimeUnit;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;

/**
 * 启动类
 * 
 * @author Wang Peng
 * @date 2022-12-10
 */
@SpringBootApplication
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
public class UnitJobAgentApplication {

    public static void main(String[] args) {
        SpringApplication.run(UnitJobAgentApplication.class, args);
    }

    @Bean
    RestTemplate restTemplate() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectionPool(pool()).connectTimeout(3, TimeUnit.SECONDS).readTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS).retryOnConnectionFailure(false);

        RestTemplate restTemplate = new RestTemplate(new OkHttp3ClientHttpRequestFactory(builder.build()));
        return restTemplate;
    }

    @Bean
    public ConnectionPool pool() {
        return new ConnectionPool(5, 25, TimeUnit.SECONDS);
    }

}
